//
//  HZWPictureTableViewCell.m
//  开心一刻
//
//  Created by lanou on 16/4/7.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "HZWPictureTableViewCell.h"

@implementation HZWPictureTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.aoturImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 40, 40)];
        self.aoturImage.layer.masksToBounds = YES;
        self.aoturImage.layer.cornerRadius = 20;
        
       self.aoturName = [[UILabel alloc]initWithFrame:CGRectMake(65, 15, 200, 20)];
        self.aoturName.font = [UIFont systemFontOfSize:13];
        self.passTime = [[UILabel alloc]initWithFrame:CGRectMake(65, 30, 200, 15)];
        self.passTime .font = [UIFont systemFontOfSize:11];
        
        self.jubaoButon =[UIButton buttonWithType:UIButtonTypeSystem];
        self.jubaoButon.frame = CGRectMake(KedWidth -45, 30, 30, 20);
        self.jubaoButon .font = [UIFont systemFontOfSize:13];
        [self.jubaoButon setTitle:@"举报" forState:UIControlStateNormal];
        [self.jubaoButon setTintColor:[UIColor orangeColor]];
        
        self.contentLabel =[[UILabel alloc]initWithFrame:CGRectMake(15, 65,KedWidth-30, 200)];
        self.contentLabel.font =[UIFont systemFontOfSize:15];
        self.contentLabel.numberOfLines = 0;
        
        self.BetterTextlabel = [[UILabel alloc]init];
        self.BetterTextlabel.font = [UIFont systemFontOfSize:15];
        
        self.style = [[UILabel alloc]init];
        self.style.font = [UIFont systemFontOfSize:13];
        
        [self.contentView addSubview:_aoturImage];
        [self.contentView addSubview:_aoturName];
        [self.contentView addSubview:_passTime];
        [self.contentView addSubview:_contentLabel];
        [self.contentView addSubview:_BetterTextlabel];
        [self.contentView addSubview:_style];
        [self.contentView addSubview:_jubaoButon];
    }
    return self;
}
// 动态返回 content的高度的方法
-(void)cellConfigureModel:(HZWPictureModel *)model
{
    self.contentLabel.text = model.text;
    if (model.style1 !=nil) {
        self.style.text =[NSString stringWithFormat:@"--%@  ",model.style1];
    }
    if (model.style2 != nil) {
        self.style.text =[NSString stringWithFormat:@"--%@ %@ ",model.style1,model.style2];
    }
     if (model.style3!= nil){
        self.style.text =[NSString stringWithFormat:@"--%@ %@ %@ ",model.style1,model.style2,model.style3];
    }
     if (model.style4 != nil){
        self.style.text =[NSString stringWithFormat:@"--%@ %@ %@ %@",model.style1,model.style2,model.style3,model.style4];
    }
    
    CGRect bounds =[model.text boundingRectWithSize:CGSizeMake(KedWidth-30, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    // 得到了content的高度  确定contentLabel 的位置
    self.contentLabel.frame = CGRectMake(15, 65, KedWidth-30, bounds.size.height);
    // 因为有的cell上没有content 和category_name 所以我们要进行判断
    if (model.betterText != nil)
    {
        self.BetterTextlabel.text = [NSString stringWithFormat:@"%@:%@",model.userName,model.betterText];
        self.BetterTextlabel.frame = CGRectMake(15, 15+40+5+bounds.size.height+5, KedWidth-30, 60);
         self.BetterTextlabel.numberOfLines = 0;
        self.style.frame =CGRectMake(15, 60+bounds.size.height+5+60, 150, 20);
    }
    else{
        
        self.BetterTextlabel.text = nil;
        self.style.frame = CGRectMake(15, 60+bounds.size.height+5, 150, 20);
        
    }
    
}
// 动态返回cell高度的类方法
+(CGFloat)cellHeghtForRow:(HZWPictureModel *)model
{
    CGRect bounds = [model.text boundingRectWithSize:CGSizeMake(KedWidth-30, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    if (model.betterText != nil) {
        return 60+bounds.size.height+5+60+20;
    }
    else{
        return 15+40+5+bounds.size.height+20+5;
    }
    
    
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
